<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改材料商发票')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-supplier-edit" th:object="${ytBillMaterialSupplier}">
            <input name="materialSupplierInvoiceId" th:field="*{materialSupplierInvoiceId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">发票金额：</label>
                <div class="col-sm-8">
                    <input id="auto" name="invoiceMoney" th:field="*{invoiceMoney}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">税率：</label>
                <div class="col-sm-8">
                    <select id="taxrate"  name="taxRate" class="form-control m-b" th:with="type=${@dict.getType('sys_material_tax')}" required>
                        <option th:id="${dict.dictLabel}" th:each="dict : ${type}" th:text="${dict.dictLabel}" th:field="*{taxRate}" th:value="${dict.dictValue}">
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">税额：</label>
                <div class="col-sm-8">
                    <input name="tax" th:field="*{tax}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合计金额：</label>
                <div class="col-sm-8">
                    <input name="amountInTotal" id="taxsum"  th:field="*{amountInTotal}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">合同状态：</label>
                <div class="col-sm-8">
                    <select name="contractStates" class="form-control m-b" th:with="type=${@dict.getType('sys_contract_states')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{contractStates}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/supplier";
        $("#form-supplier-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-supplier-edit').serialize());
            }
        }

        $('#taxrate').change(function() {
            var a = $("#auto").val();
            var d = $(this).children('option:selected').attr("id");

            function f(d) {
                var str = d.replace("%","");
                str = str/100;
                return str;
            }
            f(d);
            var c = f(d);
            var sum = a*c;
            var sum2 = Number(a) + Number(sum);
            $('#tax').val(sum.toFixed(2));
            $('#taxsum').val(sum2.toFixed(2));
        })

        // var obj = document.getElementById("#test");
        $(function () {

            $('#auto').bind('input propertychange',function () {

                var a = $("#auto").val();
                console.log("a")
                var b = $('#taxrate option:selected').attr("id");
                function f(b) {
                    var str = b.replace("%","");
                    str = str/100;
                    return str;
                }
                f(b);
                var c = f(b);
                var sum = a*c;
                var sum2 = Number(a) + Number(sum);

                $('#tax').val(sum.toFixed(2));
                $('#taxsum').val(sum2.toFixed(2));
            });
        })
    </script>
</body>
</html>